#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 310;
const int M = 6010;
const int inf = 0x3f3f3f3f;

int cnt = 1,h[N],now[N],d[N],s,t,maxflow,n,m,to[N];
bool mark[N];

struct edge{int v,w,nxt;}e[M<<2];

void link(int x,int y,int w){
	e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;
	e[++cnt] = (edge){x,0,h[y]};h[y] = cnt;
}

bool bfs(){
	memset(d,0,sizeof(d)); memset(now,0,sizeof(now));
	d[s] = 1; now[s] = h[s]; queue<int> q; q.push(s);
	while(q.size()){
		int x = q.front(); q.pop();
		for(int i = h[x];i;i = e[i].nxt){
			int y = e[i].v;
			if(!d[y] && e[i].w){
				d[y] = d[x] + 1;
				now[y] = h[y]; if(y == t) return 1;
				q.push(y);
			}
		}
	}return 0;
}

int dfs(int x,int flow){
	if(x == t) return flow; int res = flow;
	for(int i = now[x];i&&res;i = e[i].nxt){
		now[x] = i; int y = e[i].v;
		if(d[y] == d[x] + 1 && e[i].w){
			int k = dfs(y,min(flow,e[i].w));
			if(!k) d[y] = 0; else {to[x] = y;if(x != s) mark[y-n] = 1;}
			res -= k; e[i].w -= k; e[i^1].w += k;
		}
	}return flow - res;
}

void dinic(){
	int flow = 0;
	while(bfs()) while(flow = dfs(s,inf)) maxflow += flow;
	for(int i = 1;i <= n;i++){
		if(!mark[i]){
			vector<int> res;
			int x = i; res.pb(x);
			while(to[x]) res.pb(to[x] - n) , x = to[x] - n;
			for(int j = 0;j < res.size();j++) printf("%d%c",res[j]," \n"[j + 1 == res.size()]);
		}
	}
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,m = in;
	s = 0,t = 2 * n + 1;
	for(int i = 1;i <= n;i++) link(s,i,1) , link(i+n,t,1);
	for(int i = 1;i <= m;i++){
		int x = in,y = in;
		link(x,y + n,1);
	}dinic();
	printf("%d\n",n-maxflow);
	return 0;
}

